package com.cryptoneedle.center.source.repository.constraint;


import com.bubbles.engine.data.core.repository.BaseRepository;
import com.cryptoneedle.center.source.entity.constraint.ConstraintPrimary;
import com.cryptoneedle.center.source.key.constraint.ConstraintColumnKey;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>description: 源数据源-主键约束 </p>
 *
 * @author CryptoNeedle
 * @date 2025-06-20
 */
@Repository
public interface ConstraintPrimaryRepository extends BaseRepository<ConstraintPrimary, ConstraintColumnKey> {

    @Query("  FROM ConstraintPrimary " +
            "WHERE catalogName = :catalogName " +
            "ORDER BY catalogName, databaseName, tableName, constraintName, position")
    List<ConstraintPrimary> constraintPrimaries(String catalogName);

    @Query("  FROM ConstraintPrimary " +
            "WHERE catalogName = :catalogName " +
            "  AND databaseName = :databaseName " +
            "ORDER BY catalogName, databaseName, tableName, constraintName, position")
    List<ConstraintPrimary> constraintPrimaries(String catalogName, String databaseName);

    @Query("  FROM ConstraintPrimary " +
            "WHERE catalogName = :catalogName " +
            "  AND databaseName = :databaseName " +
            "  AND tableName = :tableName " +
            "ORDER BY catalogName, databaseName, tableName, constraintName, position")
    List<ConstraintPrimary> constraintPrimaries(String catalogName, String databaseName, String tableName);

    @Query("  FROM ConstraintPrimary " +
            "WHERE catalogName = :catalogName " +
            "  AND databaseName = :databaseName " +
            "  AND tableName = :tableName " +
            "  AND columnName = :columnName " +
            "ORDER BY catalogName, databaseName, tableName, constraintName, position")
    List<ConstraintPrimary> constraintPrimaries(String catalogName, String databaseName, String tableName, String columnName);
}